const connection = require('./mysql');

/**
 * 
 * @param {object} options
 * @param {string} options.event  // t logdebug, click
 * @param {string} options.member_id  //
 */
module.exports = function(sqlwhere, page, callback) {
  page = page || 0;
  sqlwhere = sqlwhere || '1 = 1'
  const sqlCount =  `select count(*) as logsum from xt_buried_point_process where ${sqlwhere}`;
  const sql = ` select * from xt_buried_point_process where ${sqlwhere} order by create_time desc limit ${page},20`;
  connection.query(sqlCount, function (error, results, fields) {
    if (error) return callback(error);
    const logsum = results[0].logsum;
    connection.query(sql, function (error, results, fields) {
      if (error) callback(error);
      const _results = [];
      results.forEach(element => {
        const remark = JSON.parse(element.remark);
        delete element.remark;
        _results.push(Object.assign({}, remark, element));
      });
      callback(null, {
        list: _results,
        count: logsum,
        page: 20
      })
    });
  
  });


}